<template>
	<view class="content bgGray">
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<view
				class="flex-r bgWhite jsb p16 ver-c"
				style="border-bottom: 1rpx solid #eee"
				v-for="item of dataList"
				:key="item.tCommodityid"
			>
				<view class="flex-r ver-c jsb" style="width: 100%" @tap="todetail(item, 'detail')">
					<view class="f1 flex-r ver-c fs14">
						<image
							:src="getImgUrl(item.tCommodityimg)"
							mode="aspectFill"
							style="width: 100rpx; height: 100rpx"
						></image>
						<view class="ml16">
							<view>{{ item.tCommodityname }}</view>
							<view class="mt10" style="color: #999;">
								{{
									item.tExaminestatus == 1 ? '审核中' : item.tExaminestatus == 2 ? '已通过' : '未通过'
								}}
							</view>
						</view>
					</view>
					<view class="flex-r fs13">
						<view class="gray" @tap="todetail(item, 'edit')">编辑</view>
						<view class="red ml16" @click.stop="delate(item.tCommodityid, item.tCommodityname)">删除</view>
					</view>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
import { ImgIP } from '@/utils/comm.js'
import Utils from '@/utils/utils.js'
import { getShopGoodList, goodDete } from '@/api/goods.js'
export default {
	data() {
		return {
			tMerchantid: '',
			dataList: []
		}
	},
	onShow() {},
	onLoad(option) {
		//this.getList()
		this.tMerchantid = option.tMerchantid
		uni.$on('updateGoodList', res => {
			if (res) {
				this.$refs.paging.reload()
			}
		})
	},
	onUnload() {
		uni.$off('updateGoodList')
	},
	methods: {
		getStatusClass(status) {
			if (status == 1) return 'yellow'
			if (status == 2) return 'green'
			return 'red'
		},
		getImgUrl(image) {
			if (image == '') {
				return 'https://www.helloimg.com/i/2024/09/06/66dac3200f428.png'
			} else {
				let imageArr = image.split(',')
				let images = imageArr[0]
				return ImgIP + images
			}
		},
		queryList(pageNo, pageSize) {
			getShopGoodList(pageNo, pageSize, this.tMerchantid).then(
				res => {
					console.log(res)
					this.$refs.paging.complete(res.rows)
				},
				err => {
					this.$refs.paging.complete(false)
				}
			)
		},
		// 删除
		delate(tCommodityid, tCommodityname) {
			Utils.showModel(`你确定要删除${tCommodityname}吗`).then(
				() => {
					goodDete(tCommodityid).then(res => {
						console.log(res)
						Utils.toast(res.msg)
						this.$refs.paging.reload()
					})
				},
				err => {
					console.log(err)
					console.log('取消')
				}
			)
		},
		todetail(item, type) {
			uni.navigateTo({
				url: `/pages_D/goodsControl/goodsControl?data=${encodeURIComponent(JSON.stringify(item))}&type=${type}`
			})
		}
	}
}
</script>

<style lang="stylus" scoped>
.content
	min-height 100%
.btn1
	font-size 26rpx
	background #c40414
	border-radius 20rpx
	color #fff
	padding 6rpx 16rpx
.btn2
	font-size 26rpx
	border 1rpx solid #c40414
	border-radius 20rpx
	color #c40414
	padding 6rpx 16rpx
</style>
